//
//  ChapterList.m
//  UMDReader
//
//  Created by 张 霄鹤 on 10-1-7.
//  Copyright 2010 xhzhang. All rights reserved.
//

#import "ChapterList.h"

#import "Chapter.h"


@implementation ChapterList

- (id)init{
	if(self = [super init]){
		chapters = [[NSMutableArray alloc] init];
	}
	return self;
}

- (NSInteger)indexOf:(NSString *)title{
	NSInteger len = [chapters count];
	NSInteger ret = -1;
	for(int i = 0;i<len;i++){
		Chapter *cp = (Chapter *)[chapters objectAtIndex:i];
		if([cp.title isEqualToString:title]){
			ret = i;
			break;
		}
	}
	return ret;
}

- (void)insert:(NSInteger)index withObject:(id)obj{
	[chapters insertObject:obj atIndex:index];
}

- (void)remove:(NSString *)key{
	NSInteger index = [self indexOf:key];
	if(index > -1){
		[chapters removeObjectAtIndex:index];
	}
}

- (void)addObject:(id)obj{
	[chapters addObject:obj];
}

- (NSInteger)count{
	return [chapters count];
}

- (id)objectAtIndex:(NSUInteger)index{
	return [chapters objectAtIndex:index];
}

- (void)dealloc{
	[chapters release];
	[super dealloc];
}

@end
